package com.example.administrator.zhjt.activity;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleAdapter;

import com.example.administrator.zhjt.R;
import com.example.administrator.zhjt.adapter.EnvironmentAdapter;
import com.example.administrator.zhjt.adapter.GuideAdapter;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener, View.OnClickListener {

    private GuideAdapter guideAdapter;
    private List<View> views;
    private ViewPager viewPager;

    private ImageView[] dot;
    private int[] ids={R.id.ids1,R.id.ids2,R.id.ids3};
    private Button enter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.guide_layout);
        initView();
        initDots();
    }

    private void initView(){
        final LayoutInflater layoutInflater=LayoutInflater.from(this);
        views=new ArrayList<>();
        views.add(layoutInflater.inflate(R.layout.guide_img1,null));
        views.add(layoutInflater.inflate(R.layout.guide_img2,null));
        views.add(layoutInflater.inflate(R.layout.guide_img3,null));

        guideAdapter=new GuideAdapter(views,this);
        viewPager= (ViewPager) findViewById(R.id.viewpage);
        viewPager.setAdapter(guideAdapter);
        viewPager.setOnPageChangeListener(this);
        enter= (Button) views.get(2).findViewById(R.id.button);
        enter.setOnClickListener(this);
    }

    private void initDots(){
        dot=new ImageView[ids.length];
        for (int i=0;i<views.size();i++){
            dot[i]= (ImageView) findViewById(ids[i]);
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        for (int i=0;i<ids.length;i++){
            if (position==i){
                dot[i].setImageResource(R.drawable.round_accent);
            }else {
                dot[i].setImageResource(R.drawable.round_primary);
            }
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onClick(View v) {
        Intent intent=new Intent(GuideActivity.this, EnvironmentActivity.class);
        startActivity(intent);
    }
}
